/**
 * 人性化时间
 * @param {Object} timestamp
 */
function beautifyTime(timestamp){
    var mistiming = Math.round(new Date() / 1000)-timestamp;
    var postfix = mistiming>0 ? '前' : '后'
    mistiming = Math.abs(mistiming)
    var arrr = ['年','个月','周','天','小时','分钟','秒'];
    var arrn = [31536000,2592000,604800,86400,3600,60,1];
 
    for(var i=0; i<7; i++){
        var inm = Math.floor(mistiming/arrn[i])
        if(inm!=0){
            return inm+arrr[i] + postfix
        }
    }
}
/**
 * 格式化时间
 * @param {Object} time
 * @param {Object} fmt
 */
function formatTime(time, fmt) {
	if (time == null) {
		return;
	}
	var fmt = fmt ? fmt : 'yyyy-MM-dd hh:mm:ss';
	var time = new Date(time);
	var z = {
			M: time.getMonth() + 1, 
			d: time.getDate(), 
			h: time.getHours(),
			m: time.getMinutes(),
			s: time.getSeconds()
		};
	fmt = fmt.replace(/(M+|d+|h+|m+|s+)/g, function(v) {
			return ((v.length > 1 ? "0" : "") + eval('z.' + v.slice(-1))).slice(-2);
		});
	return fmt.replace(/(y+)/g, function(v) {
			return time.getFullYear().toString().slice(-v.length);
		});
}
//js获取当前时间
function getNowDate() {
    var myDate = new Date;
    var year = myDate.getFullYear(); //获取当前年
    var mon = myDate.getMonth() + 1; //获取当前月
    var date = myDate.getDate(); //获取当前日
    var hours = myDate.getHours(); //获取当前小时
    var minutes = myDate.getMinutes(); //获取当前分钟
    var seconds = myDate.getSeconds(); //获取当前秒
    var now = year + "-" + mon + "-" + date + " " + hours + ":" + minutes + ":" + seconds;
    return now;
}
//获取当前时间戳
function getTimestamp() {
    return new Date(getNowDate()).getTime();
}
export default {  
	beautifyTime,
	getNowDate
}